#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'

$: << "." # Adding the local directory to the path, so we can safely require models, controllers and views.

# default options
OPTIONS = {
  :environment      => "development",
  :name             => "#{Dir.pwd.split("/").last}",
}

ARGV.options do |o|
  script_name = File.basename($0)
  
  o.set_summary_indent('  ')
  o.banner =    "Usage: script/#{script_name} [OPTIONS]"
  o.define_head "Runs the Skates Application."
  o.separator   ""
  o.separator   "Arguments :" 
  
  o.on("-e", "--environment=env", String,
       "The environment to run the application (you should have defined the argument into config/config.yaml)",
       "Default: #{OPTIONS[:environment]}") { |environment| 
         OPTIONS[:environment] = environment
        }
  o.on("-n", "--name=app_name", String,
       "Name of your application. The pid_file will be name after this.",
       "Default: #{OPTIONS[:name]}") { |name| 
         OPTIONS[:name] = name
        }
  
  o.separator ""

  o.on_tail("-h", "--help", "Show this help message.") { puts o; exit }
  
  o.parse!
end

$appname        = OPTIONS[:name]
SKATES_ENV      = OPTIONS[:environment]
require File.dirname(__FILE__) + '/../config/boot.rb'
